﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Flame.Dlr;
using System.Reflection;
using System.IO;
using System.Drawing;

namespace Flame.Controls 
{
    public class ScripterControlFormInfo
    {
        public ScripterControlForm ScripterControlForm { get; private set; }
        public ScripterTabbedControl ScripterTabbedControl { get; private set; }
        public Manager Dlr { get { return ScripterTabbedControl.ScripterLoaderControl.ScripterControl.Manager; } }
        //public VerticalPanelScroll VerticalPanelScroll { get; private set; }


        public ScripterControlFormInfo(ScripterControlForm scripterControlForm, ScripterTabbedControl scripterTabbedControl)
        {
            ScripterControlForm = scripterControlForm;
            ScripterTabbedControl = scripterTabbedControl;
        }
    }

    public class ScripterControlFormSettings
    {

        public string DefaultLanguage { get; private set; }
        public Type TextinputResolverType { get; private set; }
        public ManagerSettings ManagerSettings { get; private set; }

        public ScripterControlFormSettings(Type itextinputResolverType, ManagerSettings managerSettings, string defaultLanguage = "None")
        {
            DefaultLanguage = defaultLanguage;
            TextinputResolverType = itextinputResolverType;
            ManagerSettings = managerSettings;
        }
    }

    public class ScripterControlForm : Form
    {

        public ScripterControlFormInfo ScripterControlFormInfo { get; set; }
        public OutputStreamWindow OutputStreamWindow { get { return ScripterControlFormInfo.ScripterTabbedControl.ScripterLoaderControl.ScripterControl.OutputStreamWindow; } }

        public ScripterControlForm(ScripterControlFormSettings settings, string docPath = null)
            : this(settings, new ScopeParameters(), docPath)
        {
        }

        public ScripterControlForm(ScripterControlFormSettings settings, ScopeParameters scopeParameters, string docPath = null)
        {
            var scripterTabbedControl = new ScripterTabbedControl(scopeParameters, settings);
            ScripterControlFormInfo = new Flame.Controls.ScripterControlFormInfo(this, scripterTabbedControl);


            scopeParameters.Variables.Add(new Variable() { Name = "flame", Data = ScripterControlFormInfo });

            Icon = Properties.Resources.flame;
            Text = "Flame";

            ScripterControlFormInfo.ScripterTabbedControl.Dock = DockStyle.Fill;
            Controls.Add(ScripterControlFormInfo.ScripterTabbedControl);
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            //if(ScripterControlFormInfo.ScripterTabbedControl != null)
                ScripterControlFormInfo.ScripterTabbedControl.AskForClose(e);
        }

    }
}
